package com.youka.bussiness.controller.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import com.youka.bussiness.common.bean.RestResp;
import com.youka.bussiness.common.base.BaseEntity;
import com.youka.bussiness.common.base.BaseController;
import com.youka.bussiness.service.ProductsService;
import com.youka.bussiness.service.req.ProductsReqDto;
import com.youka.bussiness.service.req.ProductsUpdateDto;
import com.youka.bussiness.service.req.ProductsPageDto;
import com.youka.bussiness.service.res.ProductsDto;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.List;


import java.util.Map;

/**
 * 产品信息表 Controller
 *
 * @author lfc
 * @date 2024-06-30 16:47:28
 */
@Api(tags = "web-产品信息表")
@RestController()
@RequestMapping("/web/Products")
public class ProductsController extends BaseController{

    @Autowired
    private ProductsService productsService;

    /**
     * 查询产品信息表详情
     */
    @ApiOperation(value = "获取产品信息表详情")
    @PostMapping(value = "/single")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询产品信息表详情", response = ProductsDto.class)
    })
    public RestResp findProductsById(@RequestBody BaseEntity entity) {
        ProductsDto dto = productsService.selectById(entity.getId());
        return success(dto);
    }

    /**
     * 查询产品信息表集合
     */
    @ApiOperation(value = "查询产品信息表集合")
    @PostMapping("/list")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询产品信息表详情", response = ProductsDto.class)
    })
    public RestResp listProducts(@RequestBody ProductsReqDto productsPageDto) {
        List<ProductsDto> list = productsService.selectByList(productsPageDto);
        return success().toAdminTree(list);
    }

    /**
     * 查询产品信息表分页
     */
    @ApiOperation(value = "查询产品信息表分页")
    @PostMapping("/page")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询产品信息表详情", response = ProductsDto.class)
    })
    public RestResp pageProducts(@RequestBody ProductsPageDto productsPageDto) {
        IPage<ProductsDto> page = productsService.selectByPage(productsPageDto);
        return success().toAdminPage(page);
    }

    /**
     * 新增产品信息表
     */
    @ApiOperation(value = "新增产品信息表")
    @PostMapping("/add")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询产品信息表详情", response = RestResp.class)
    })
    public RestResp addProducts(@RequestBody ProductsReqDto productsReqDto) {
        productsService.insert(productsReqDto);
        return success();
    }

    /**
     * 编辑产品信息表
     */
    @ApiOperation(value = "编辑产品信息表")
    @PostMapping("/update")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询产品信息表详情", response = RestResp.class)
    })
    public RestResp updateProducts(@RequestBody ProductsUpdateDto productsReqDto) {
        productsService.update(productsReqDto);
        return success();
    }

    /**
     * 删除产品信息表主键
     */
    @ApiOperation(value = "删除产品信息表")
    @PostMapping("/delete")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询产品信息表详情", response = RestResp.class)
    })
    public RestResp delete(@RequestBody BaseEntity entity) {
        productsService.deleteById(entity.getId());
        return success();
    }

}
